﻿Sys.Mvc.ValidatorRegistry.validators["passwordLength"] = function (rule) {
    // initialization code can go here.
    var minValue = rule.ValidationParameters["min"];

    // we return the function that actually does the validation 
    return function (value, context) {
        if (value.length >= minValue) {
            return true; /* success */
        }

        return rule.ErrorMessage;
    };
};

Sys.Mvc.ValidatorRegistry.validators.mustMatch = function (rule) {
    var propertyIdToMatch = rule.ValidationParameters.propertyIdToMatch;
    var message = rule.ErrorMessage;

    return function (value, context) {
        var thisField = context.fieldContext.elements[0];
        var otherField = $get(propertyIdToMatch, thisField.form);
        
        if (otherField.value != value) {
            return false;
        }

        return true;

    };
}; 